<template>
<div>
    <div v-for="item in dataList">
        <input type="hidden"  v-model="item.id" >
         商品编号：<input type="text" v-model="item.code" ><br/>
         商品名称:<input type="text" v-model="item.name" ><br/>
         型号:<input type="text" v-model="item.model"><br/>
         单位:<input type="text" v-model="item.unit"><br/>
         上次进价:<input type="text" v-model="item.lastPurchasingPrice"><br/>
         添加数量:<input type="text"  v-model="item.inventoryQuantity"><br/>
        <input type="button" @click="save()" value="添加">
    </div>
</div>
</template>
<script>
export default {
     data(){
      return {
        tableData:[],
        currentPage:1,
        pageSizes:[1, 2, 3, 4,5],
        pageSize:1,
        total:5,
        dataList:[]
    }
  },mounted(){
      this.requestData();


  },methods:{
     handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.pageSize = val;
         this.requestData();
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.currentPage = val;
        this.requestData();


      }
  },mounted(){
      var id = this.$route.params.id;
      console.log("------"+id)
        var formData=new FormData();
        formData.append('id',id);
        var api="http://localhost:8089/admin/goods/toAdd";
        this.$http.post(api,formData).then(function(data){
            console.log(data);
            if(data.body.code=='10000'){
                alert(data.body.msg);
                this.dataList=data.body.tableData;
            }
        })
        
      },methods:{
        save(){
            var id=this.dataList[0].id;
            var code=this.dataList[0].code;
            var name=this.dataList[0].name;
            var model=this.dataList[0].model;
            var unit=this.dataList[0].unit;
            var lastPurchasingPrice=this.dataList[0].lastPurchasingPrice;
            var inventoryQuantity=this.dataList[0].inventoryQuantity;
            var formDate =new FormData();
            formDate.append('id',id);
            formDate.append('code',code);
            formDate.append('name',name);
            formDate.append('model',model);
            formDate.append('unit',unit);
            formDate.append('lastPurchasingPrice',lastPurchasingPrice);
            formDate.append('inventoryQuantity',inventoryQuantity);
            var api='http://localhost:8089/admin/goods/tosave';
            this.$http.post(api,formDate).then(function(data){
            if(data.body.code=='10000'){
               // alert(data.body.msg);
               window.location.href="http://localhost:8080/#/list";
            }
             alert(data.body.msg);
         })
        }
      }
} 
</script>
